package cn.edu.web.原始Servlet;

import cn.edu.pojo.Brand;
import cn.edu.service.BrandService;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Davey chan
 */
//@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {
    private BrandService brandService = new BrandService();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//调用service的查询
        List<Brand> brands = brandService.selectAll();
//将集合转换成JSON数据，也叫序列化
        String jsonString = JSON.toJSONString(brands);
//        响应数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);


    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }


}
